const puppeteer = require('puppeteer');
// const request = require('request');
const cheerio = require('cheerio');

// request('https://www.xiaohongshu.com/explore/65acaf09000000002d034cec', (error, response, html) => {

//   if (!error && response.statusCode == 200) {
//     const $ = cheerio.load(html);

//     const a = $('#app .engage-bar .engage-bar-container');
//     // console.log($.parseHTML(siteHeading));
//     console.log(a.html());
//   }
// });

async function run() {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://www.xiaohongshu.com/explore/65ad360e000000000c007aff');

  // 等待某一个元素加载完成
  await page.waitForSelector('#app');

  // 将完整页面的HTML抓取到
  let bodyHTML = await page.evaluate(() => document.body.innerHTML);

  // 使用cheerio解析
  let $ = cheerio.load(bodyHTML);
  // 从这开始你可以用cheerio解析你需要的内容
  // ...
  const a = $('#app .engage-bar .engage-bar-container .like-wrapper .count');
  // console.log($.parseHTML(siteHeading));
  console.log(a.html());
  await browser.close();
}

run();